/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jmeshless;

import Integration.GaussQuadrature;
import Integration.IFunction1D;
import MF1DSolver.MF1DSolver;
import MeshlessShapeFunctions.IKernelFunction;
import MeshlessShapeFunctions.JGaussian;
import MeshlessShapeFunctions.JMeshlessInterpolationFunction1D;
import MeshlessShapeFunctions.Particle;
import java.util.ArrayList;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 *
 * @author mark_o
 */
public class NewClass {
    public static void main(String[] args){


        double left = 0.0;
        boolean DirihletA = true;
        boolean DirihletB = true;
        double right = 0.0;
        String p = "1";
        String q = "0";
        String w = "100";
        String f = "100";


        IKernelFunction kernal = new JGaussian(1);
                /*switch(jComboBox4.getSelectedIndex()){
        case 0: kernal = new JGaussian(); break;
        case 1: kernal = new JCubicSpline(); break;
        case 2: kernal = new JExponential(0.7); break;
        case 3: kernal = new JStKernel(); break;
        //case 4: kernal = new JSt2Kernel(); break;
        default: kernal = new JGaussian();
        }*/
        double a =0.0,b=0.5;
        int n = 30, Degree = 1;
            double rho = 4;
            ArrayList<Particle> ls1D = new ArrayList<Particle>();
            final ArrayList<JMeshlessInterpolationFunction1D> MeshlessShapeList = new ArrayList<JMeshlessInterpolationFunction1D>();
            double h = (b-a-rho*0.05)/(double)n;
            for (int i = 0; i <n; i++) {
                ls1D.add(new Particle(a+h*i, 0, i));
                MeshlessShapeList.add(new JMeshlessInterpolationFunction1D(Degree, a+i*h, rho*h, kernal));
            }

            a=0.5;
            b=1.0;
            rho = 4;
            n=5;
            h = (b-a)/(double)n;
            for (int i = 0; i <=n; i++) {
                ls1D.add(new Particle(a+h*i, 0, i));
                MeshlessShapeList.add(new JMeshlessInterpolationFunction1D(Degree, a+i*h, rho*h, kernal));
            }

            a=0.0;
            b=1.0;

            MF1DSolver solver = new MF1DSolver();
            solver.setfString(f);
            solver.setwString("-"+w);
            solver.setqString(q);
            solver.setpString(p);
            solver.setAVal(left);
            solver.setBVal(right);
            solver.setDirihetA(DirihletA);
            solver.setDirihetB(DirihletB);
            solver.setRight(b);
            solver.setLeft(a);

            solver.setListOfShapeFunction(MeshlessShapeList);
            solver.setNodeList(ls1D);


            long startTime = System.currentTimeMillis();


            solver.generate();
            final double[] res = solver.solvePenalty();

            System.out.println((System.currentTimeMillis()-startTime));


            GaussQuadrature gau = new GaussQuadrature(50);
            System.out.println(gau.Gauss(a, b, 0.000001, new IFunction1D() {

                public double calculate(double x) {
                    double tmp = 0.0;
                    for (int j = 0; j <res.length; j++) {
                        tmp+= MeshlessShapeList.get(j).calculate(x)*res[j];
                    }
                    return tmp*tmp;
                }

                public double calculateDerivaty(double x) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            }));



            XYSeries series1 = new XYSeries("розвязок методом штрафу", true, true);
            double x = 0;
            while(x<=1.0001){
                double tmp = 0.0;
                for (int j = 0; j <res.length; j++) {
                    tmp+= MeshlessShapeList.get(j).calculate(x)*res[j];
                }
                series1.add(x,tmp);
                x+=0.01;
            }

            NewOkCancelDialog dialog = new NewOkCancelDialog(null, false, new XYSeriesCollection(series1));
            dialog.setLocationRelativeTo(null);
            //dialog.setUndecorated(true);
            dialog.setVisible(true);
    }
}
